package com.yy.train.ticket.train.controller;

import java.util.Arrays;
import java.util.List;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.train.ticket.into.page.LinePage;
import com.yy.train.ticket.into.TtLine;
import com.yy.train.ticket.train.entity.TtTrainEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TtLineEntity;
import com.yy.train.ticket.train.service.TtLineService;

import com.yy.train.ticket.utils.R;



/**
 * 线路
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-27 10:03:48
 */
@RestController
@RequestMapping("tt/line")
public class TtLineController {
    @Autowired
    private TtLineService ttLineService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(){

        return R.ok(this.ttLineService.list(Wrappers.<TtLineEntity>lambdaQuery()));

    }
    @PostMapping("/page")
    public R page(@RequestBody LinePage trainPage){
        LambdaQueryWrapper<TtLineEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(trainPage.getLineName()), TtLineEntity::getLineName,trainPage.getLineName());
        Page<TtLineEntity> pages = new Page<TtLineEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtLineEntity> iPage = ttLineService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{lineId}")
    public R info(@PathVariable("lineId") Long lineId){


        return  ttLineService.getLineById(lineId);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody TtLine ttLine){
        return ttLineService.saveTtLine(ttLine);


    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TtLine ttLine){
        return ttLineService.updateTtLineById(ttLine);


    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody List<Long> lineIds){
		ttLineService.removeByIds(lineIds);

        return R.ok();
    }

}
